from flask import Flask, request, render_template, json, session, redirect
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import asc, desc

from flask_migrate import Manager,MigrateCommand
from flask_script import Manager

app = Flask(__name__)

app.config.from_pyfile("config.py")

db = SQLAlchemy(app)


class User(db.Model):
    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    username = db.Column(db.String(50), unique=True, nullable=False)

    password = db.Column(db.String(150), nullable=True)

    age = db.Column(db.Integer, nullable=False)


class Blog(db.Model):
    __tablename__ = "blog"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    title = db.Column(db.String(50), unique=True, nullable=False)

    author = db.Column(db.String(150), nullable=True)

    content = db.Column(db.Integer, nullable=False)


# @app.route("/init")
# def init():
#     db.create_all()
#     return "数据库创建成功"
#
# @app.route("/add", methods=["GET", "POST"])
# def add():
#     if request.method == "POST":
#         username2 = User(username=request.form.get("username"), password=request.form.get("password"),
#                          age=request.form.get("age"))
#         db.session.add(username2)
#
#         db.session.commit()
#         return "添加成功"
#     return render_template("login.html")
# @app.route("/sort")
def sort():
    sort = User.query.order_by(User.id).all()
    print(sort)


if __name__ == '__main__':
    sort()
